package org.balabala.user.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.balabala.user.entity.FollowInfoEntity;
import org.balabala.user.service.FollowInfoService;
import org.balabala.user.utils.PageUtils;
import org.balabala.user.utils.Resp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;





/**
 * 
 *关注信息
 * @author hanshanxi
 * @email 3176988793@qq.com
 * @date 2021-09-04 09:31:53
 */
@RestController
@RequestMapping("balabala/follow")
public class FollowInfoController {
    @Autowired
    private FollowInfoService followInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    
    public Resp list(@RequestParam Map<String, Object> params){
        PageUtils page = followInfoService.queryPage(params);

        return Resp.ok().put("page", page);
    }

    @RequestMapping("listByFanId")
    public Resp listFanId(@RequestParam Long fanId,@RequestParam Integer page,@RequestParam Integer limit){
        HashMap<String,Object> hashMap = new HashMap<>();
        hashMap.put("fanId",fanId);
        hashMap.put("page",page.toString());
        hashMap.put("limit",limit.toString());
        PageUtils pageUtils = followInfoService.queryPageByFanId(hashMap);
        if(pageUtils == null){
            return Resp.error(500,"该用户暂未关注任何人");
        }else {
            return  Resp.ok().put("data",pageUtils);
        }
    }
    @RequestMapping("listByFollowedId")
    public Resp listFollowedId(@RequestParam Long followedId,@RequestParam Integer page,@RequestParam Integer limit){
        HashMap<String,Object> hashMap = new HashMap<>();
        hashMap.put("followedId",followedId);
        hashMap.put("page",page.toString());
        hashMap.put("limit",limit.toString());
        PageUtils pageUtils = followInfoService.queryPageByFollowedId(hashMap);
        if(pageUtils == null){
            return Resp.error(500,"该用户暂未被任何人关注");
        }else {
            return  Resp.ok().put("data",pageUtils);
        }
    }

    @RequestMapping("/save")
    public Resp sava(@RequestParam Long fanId,@RequestParam Long followedId){
        return  followInfoService.saveInfo(fanId,followedId);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{followId}")

    public Resp info(@PathVariable("followId") Integer followId){
		FollowInfoEntity followInfo = followInfoService.getById(followId);

        return Resp.ok().put("followInfo", followInfo);
    }

    /**
     * 信息
     */
    @RequestMapping("/info")
    public Resp info(@RequestParam Long uid,@RequestParam Integer page, @RequestParam Integer limit){
        Map<String,Object> map = new HashMap<>();
        map.put("uid",uid);
        map.put("page",page.toString());
        map.put("limit",limit.toString());

        PageUtils data = followInfoService.queryPageByUid(map);
        if(page != null){
            return  Resp.ok().put("data",data);
        }else{
            return Resp.error(500,"查询失败，请确定是否参与评论");
        }
    }



    /**
     * 保存
     */
//    @RequestMapping("/save")
//
//    public Resp save(@RequestBody FollowInfoEntity followInfo){
//		followInfoService.save(followInfo);
//        return Resp.ok();
//    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public Resp update(@RequestBody FollowInfoEntity followInfo){
		followInfoService.updateById(followInfo);

        return Resp.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Resp delete(@RequestParam Long fanId,@RequestParam Long followedId){
        return  followInfoService.delete(fanId,followedId);

    }



//    @RequestMapping("/deletebyfollowid")
//    public Resp delete(@RequestParam Long followId){
//        boolean follow_id = followInfoService.remove(new QueryWrapper<FollowInfoEntity>().eq("follow_id", followId));
//        if(follow_id){
//            return Resp.ok();
//        }else{
//            return Resp.error(500,"关注失败");
//        }
//    }


}
